import 'package:flutter/material.dart';
import 'package:flutter_trip/models/common_model.dart';
import 'package:flutter_trip/models/grid_nav_model.dart';
import 'package:flutter_trip/widget/webview.dart';

class SubNav extends StatelessWidget{
  final List<CommonModel> subNavList;
  final String name;

  SubNav(this.subNavList,{this.name='xiaoming'});

  @override
  Widget build(BuildContext context) {
     return Container(
//       height: 64,
       decoration: BoxDecoration(
           color: Colors.white,
         borderRadius:  BorderRadius.circular(6),

       ),
       child: Padding(
         padding: EdgeInsets.all(7),
         child: _items(context),
       ),
     );
  }
  
  _items(BuildContext context){
    if(subNavList == null) return null;
    List<Widget>items =[];
//    for(CommonModel m in SubNavList){
//      print(m);
//      items.add(_item(context, m));
//    }
    subNavList.forEach((element) {
      items.add(_item(context, element));

    });

    //计算每行的展示数量。
    int separate = (subNavList.length/2+0.5).toInt();

    return Column(
      children: [
      Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: items.sublist(0,separate),
    ),
      Padding(padding: EdgeInsets.only(top: 10),
      child:  Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: items.sublist(separate,subNavList.length),
      ),
      )

      ],
    );

  }
  Widget _item(BuildContext context,CommonModel model){
      return Expanded(
          child: GestureDetector(
        onTap: (){
          Navigator.push(context, MaterialPageRoute(builder: (context)=>MyWebView(model.url, model.statusBarColor, model.title, model.hideAppBar)));
        },
        child: Column(children: [
          Image.network(model.icon,height: 18,width: 18,),
          Padding(padding: EdgeInsets.only(top: 5),
            child: Text(model.title,style: TextStyle(fontSize: 12),),
          )

        ],
        ),
      ));
  }
}